package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.model.bean.RecordEmailBean;
import com.yanchangapp.ui.view.RecordEmailAtView;
import com.zxl.baselib.bean.response.BaseListResponse;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-08-30.
 * description: 采购记录邮件p层
 */
public class RecordEmailAtPresenter extends BasePresenter<RecordEmailAtView> {

    public RecordEmailAtPresenter(BaseActivity context) {
        super(context);
    }

    public void queryEmailDetail(int id){
        HeadApiRetrofit.getInstance().queryMailContent(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseListResponse<RecordEmailBean>>() {
                    @Override
                    public void onNext(BaseListResponse<RecordEmailBean> recordEmailBeanBaseListResponse) {
                        if (null != getView()){
                            getView().queryRecordEmailSuccess(recordEmailBeanBaseListResponse.getData());
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (null != getView()){
                            getView().queryRecordEmailFailure(exception.getErrorInfo());
                        }
                    }
                });
    }
}
